﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using HAUtil;

namespace HA.Data
{
    /// <summary>
    /// sh设计用于存储对应的结果数据
    /// 
    /// 存储modflow的结果数据
    /// 注意：此类不要轻易添加删除字段属性，如果要修改，需要修改就算结果的拷贝操作，在Data2Commands 中
    ///
    /// </summary>
    [Serializable]
    public class DSGrid3dCollecion:DescEntity
    {

        public DSGrid3dCollecion(string id)
            : base(id)
        {

            this._collecion = new List<DSGrid3d>();
 
        }




        public DSGrid3dCollecion()
        {
            this._collecion = new List<DSGrid3d>();
        }




        [field: NonSerialized]
        public event EventHandler<CollecionChangedEventArgs> DataSetCollectionChanged;




        List<DSGrid3d> _collecion;

        public List<DSGrid3d> Collecion
        {
            get { return _collecion; }
            set { _collecion = value; }
        }



        public DSGrid3d GetDSGrid(int index)
        {

            if (this._collecion.Count > index)
            {
                return this._collecion[index];

            }

            else
            {
                return null;
            }
 

        }


        public DSGrid3d GetDSGrid(string id)
        {
            foreach (DSGrid3d item in this._collecion)
            {
                if (id == item.Id)
                {
                    return item;

                }

            }


            return null;

        }


        public void Add(DSGrid3d ds)
        {

            DSGrid3d dsOld = this.GetDSGrid(ds.Id);

            if (dsOld==null)
            {
                this._collecion.Add(ds);


                if (DataSetCollectionChanged!=null)
                {
                    DataSetCollectionChanged(this,new CollecionChangedEventArgs (ds,CollectionChangedType.ADD));
                    
                }


                
            }



 
        }


        public void RemoveDSGrid3d(DSGrid3d ds)
        {



            if (this._collecion.Contains(ds))
            {

                this._collecion.Remove(ds);

                if (DataSetCollectionChanged != null)
                {
                    DataSetCollectionChanged(this, new CollecionChangedEventArgs(ds, CollectionChangedType.REMOVE));

                }



            }
        
        
        }



       

    }
}
